/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cratos.xxgram.platf.complaint;

import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService;
import org.redkale.service.RetResult;
import org.redkale.source.FilterFunc;
import org.redkale.source.FilterNode;

import com.cratos.xxgram.platf.base.BaseService;
import com.cratos.xxgram.platf.base.RetCodes;
import com.cratos.xxgram.platf.base.UserInfo;

/**
 *
 * @author SquRab
 */
@RestService(name = "complaint", comment = "举报信息管理服务")
public class ComplaintService extends BaseService {

	@RestMapping(name = "addComplaintRecord", auth = true, comment = "举报")
	public RetResult addComplaintRecord(UserInfo userInfo, ComplaintRecord bean) {
		short complainttype = bean.getComplainttype();
		// 类型校验
		if (ComplaintType.getValue(complainttype) == null)  return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL);
		int complaintid = source
				.getNumberResult(ComplaintRecord.class, FilterFunc.MAX, 1_0000_0000, "complaintid", (FilterNode) null)
				.intValue() + 1;
		bean.setComplaintid(complaintid);
		bean.setComplaintuserid(userInfo.getUserid());
		bean.setDealstatus(ComplaintRecord.UN_DO_STATUS);// 未处理
		bean.setCreatetime(System.currentTimeMillis());
                //bean.setComplaintcontent(ComplaintType.getValue(complainttype).getDesc());
		return RetResult.success(source.insert(bean));
	}

	
	@RestMapping(name = "queryComplaintTypes", auth = true, comment = "查询举报类型")
	public RetResult queryComplaintTypes() {
		return RetResult.success(ComplaintType.toMaps());
	}

	public static void main(String[] args) throws Exception {
		System.out.println(ComplaintType.values());
//     ComplaintService service =   Application.singleton(ComplaintService.class);
//     ComplaintRecord record = new ComplaintRecord();
//     record.setComplaintcontent("涉黄。。。。");
//     record.setComplaintmodule(ComplaintRecord.GROUP_MODULE);
//     service.addComplaintRecord(UserInfo.USER_SYSTEM, record);
	}
}
